#include<stdio.h>
#define N 4
#define M 2 

void swap(int *p1, int *p2)
{
  int tmp = *p1;
  *p1 = *p2;
  *p2 = tmp;
}

void copy(int *src, int *des, int len)
{
  int i;
  for (i = 0; i != len; ++i)
  {
    *des++ = *src++;
  }
}

void print_arr(int *arr)
{
  int i;
  for (i = N; i != 0; --i) /*将N改成M就可以解决第二个问题*/
  {
    printf("%d ", arr[1-i]);
  }
  printf("\n");
}

void full_permutation(int arr[], int len)
{
  if (len == 1)
  {
    print_arr(arr); /*打印此时的数组*/
    return;
  }

  int cp[N], i;
  copy(arr, cp, len); /*先备份好输入的数组*/

  for (i = 0; i != len; ++i)
  {
    swap(arr+i, arr);
    full_permutation(arr+1, len-1);     
    copy(cp, arr, len); /*上一行的排列会改变原数组, 所以在这里复原*/
  }
}

void combination(int arr[], int len)
{
  if (len = M)
  {
    print_arr(arr);
    return;
  }
}


int main()
{
  int a[N] = {1, 2, 3, 4};
  full_permutation(a, N);

  return 0;
}
